﻿Imports LRS.DTO
Imports System.Windows.Forms

Public Class ucEmp
    Private EmpID As Integer
    Public Function ucValidateEmp() As Boolean
        If txtFirstName.Text.Length = 0 Or txtLastName.Text.Length = 0 Or txtEmail.Text.Length = 0 Or txtPhone.Text.Length = 0 Then
            MessageBox.Show("Tất cả các trường không được bổ trống!!")
            txtFirstName.Focus()
            Return False
        End If
        If txtEmail.Text Like "*@[A-Z,a-z,0-9]*.*" Then
            Return True
        Else
            MessageBox.Show("Địa chỉ Email không đúng định dạng!!")
            txtEmail.Text = ""
            txtEmail.Focus()
            Return False
        End If
        If txtPhone.Text Like "[0-9]" Then
            Return True
        Else
            MessageBox.Show("Số điện thoại không đúng định dạng!!")
            txtPhone.Text = ""
            txtPhone.Focus()
            Return False
        End If
        Return True
    End Function

    Public Sub ClearText()
        For Each c As Control In grpEmp.Controls
            If (TypeOf c Is TextBox Or TypeOf c Is RichTextBox) Then
                c.ResetText()
            End If
        Next
        cmbPermission.SelectedItem = "User"
        txtPassword.Text = ""
    End Sub
    Public Sub SetEmployee(ByVal emp As eEmployee)
        txtPassword.Text = ""
        txtAddress.Text = emp.Address
        txtEmail.Text = emp.Email
        txtFirstName.Text = emp.FirstName
        txtLastName.Text = emp.LastName
        txtPhone.Text = emp.Phone
        dtBirthday.Value = emp.DateOfBirth
        rtxtOtherInfo.Text = emp.OtherInfo
        radFemale.Checked = emp.Gender
        cmbPermission.SelectedItem = emp.Type
        EmpID = emp.EmployeeID
    End Sub
    Public Function GetEmployee() As eEmployee
        Dim emp As eEmployee = New eEmployee()
        emp.EmployeeID = EmpID
        emp.FirstName = txtFirstName.Text
        emp.LastName = txtLastName.Text
        emp.Address = txtAddress.Text
        emp.Phone = txtPhone.Text
        emp.OtherInfo = rtxtOtherInfo.Text
        emp.Gender = radFemale.Checked
        emp.Email = txtEmail.Text
        emp.Type = cmbPermission.SelectedItem
        emp.Password = txtPassword.Text
        emp.DateOfBirth = dtBirthday.Value
        Return emp
    End Function

    Private Sub ucEmp_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        cmbPermission.SelectedIndex = 0
    End Sub

    Private Sub radMale_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles radMale.CheckedChanged
        If (radMale.Checked = True) Then
            radFemale.Checked = False
        End If
    End Sub
End Class
